#ifndef __LG_GDI_H__
#define __LG_GDI_H__


#define GUI_DEFAULT_FONT    &GUI_FontHZ_SimSun_13

#define GUI_LOCK()
#define GUI_UNLOCK()
#define GUITASK_INIT()
#define GUITASK_COPY_CONTEXT()

/* Text alignment flags, horizontal */
#define GUI_TA_HORIZONTAL  (3<<0)
#define GUI_TA_LEFT        (0<<0)
#define GUI_TA_RIGHT	     (1<<0)
#define GUI_TA_CENTER	     (2<<0)
#define GUI_TA_HCENTER	   GUI_TA_CENTER  /* easier to remember :-)  */

/* Text alignment flags, vertical */
#define GUI_TA_VERTICAL   (3<<2)
#define GUI_TA_TOP	      (0<<2)
#define GUI_TA_BOTTOM	    (1<<2)
#define GUI_TA_BASELINE   (2<<2)
#define GUI_TA_VCENTER    (3<<2)

/*
****************************************
*                                      *
*      FONT info structure             *
*                                      *
****************************************

This structure is used when retrieving information about a font.
It is designed for future expansion without incompatibilities.
*/
typedef struct {
  WORD Flags;
  BYTE Baseline;
  BYTE LHeight;     /* height of a small lower case character (a,x) */
  BYTE CHeight;     /* height of a small upper case character (A,X) */
} GUI_FONTINFO;

#define GUI_FONTINFO_FLAG_PROP (1<<0)    /* Is proportional */
#define GUI_FONTINFO_FLAG_MONO (1<<1)    /* Is monospaced */
#define GUI_FONTINFO_FLAG_AA   (1<<2)    /* Is an antialiased font */
#define GUI_FONTINFO_FLAG_AA2  (1<<3)    /* Is an antialiased font, 2bpp */
#define GUI_FONTINFO_FLAG_AA4  (1<<4)    /* Is an antialiased font, 4bpp */

/**********************************************************************
*
*                 FONT Encoding
*
***********************************************************************
*/

typedef int  tGUI_GetLineDistX(const char  *s, int Len);
typedef int  tGUI_GetLineLen(const char  *s, int MaxLen);
typedef void tGL_DispLine(const char  *s, int Len);

typedef struct {
  tGUI_GetLineDistX*          pfGetLineDistX;
  tGUI_GetLineLen*            pfGetLineLen;
  tGL_DispLine*               pfDispLine;
} tGUI_ENC_APIList;

typedef struct {
  BYTE XSize;
  BYTE XDist;
  BYTE BytesPerLine;
  const unsigned char* pData;
} GUI_CHARINFO;

typedef struct GUI_FONT GUI_FONT;

typedef void GUI_DISPCHAR(WORD c);
typedef int  GUI_GETCHARDISTX(WORD c);
typedef void GUI_GETFONTINFO(const GUI_FONT  * pFont, GUI_FONTINFO * pfi);
typedef char GUI_ISINFONT   (const GUI_FONT  * pFont, WORD c);
typedef GUI_CHARINFO* GUI_GETUNKNOWCHAR(WORD c);

typedef struct GUI_FONT_PROP {
  WORD First;                                /* first character               */
  WORD Last;                                 /* last character                */
  const GUI_CHARINFO* paCharInfo;            /* address of first character    */
  const struct GUI_FONT_PROP* pNext;        /* pointer to next */
} GUI_FONT_PROP;

typedef struct __GUI_FONT_MAP
{
    const WORD          *pCharGBK;
    const WORD              usCharsSize;
    const GUI_CHARINFO* paCharInfo;
}GUI_FONT_MAP;

struct GUI_FONT {
  GUI_DISPCHAR*     pfDispChar; 
  GUI_GETCHARDISTX* pfGetCharDistX; 
  GUI_GETFONTINFO*  pfGetFontInfo; 
  GUI_ISINFONT*     pfIsInFont;
  const tGUI_ENC_APIList* pafEncode;
  BYTE YSize;
  BYTE YDist;
  BYTE XMag;
  BYTE YMag;
  
  union {
    const void           * pFontData;    
    const GUI_FONT_MAP *pMap;
    const GUI_FONT_PROP  * pProp;
  } p;

  BYTE Baseline;
  BYTE LHeight;     /* height of a small lower case character (a,x) */
  BYTE CHeight;     /* height of a small upper case character (A,X) */
};

typedef struct
{
    BYTE        PenSize;

    WORD LBorder;
    WORD DispPosX, DispPosY;
    WORD DrawPosX, DrawPosY;
    WORD TextMode, TextAlign;    
    const tLCDDEV_API* pDeviceAPI;  /* function pointers only */
    const GUI_FONT* pAFont;
}GUI_CONTEXT;

extern GUI_CONTEXT        GUI_Context;
extern const GUI_FONT GUI_FontHZ_SimSun_13;
extern const tLCDDEV_API LCD_APIList;
extern const tGUI_ENC_APIList GUI_ENC_APIList_SJIS;

void GUIDrawRect(int x0, int y0, int x1, int y1);
void GUIFillRect(int x0, int y0, int x1, int y1);
void GUIClearRect(int x0, int y0, int x1, int y1) ;

#endif
